package com.modules.system.service.impl;

import cn.hutool.crypto.SecureUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.common.response.ResponseVO;
import com.common.exception.RRException;
import com.modules.system.entity.Admin;
import com.modules.system.mapper.AdminMapper;
import com.modules.system.service.IAdminService;
import org.springframework.stereotype.Service;

@Service("adminService")
public class AdminServiceImpl extends ServiceImpl<AdminMapper, Admin> implements IAdminService {

    /**
     * 登录
     * */
    @Override
    public ResponseVO doLogin(Admin admin) {
        String password = SecureUtil.sha1( SecureUtil.md5(admin.getPassword()));
        Admin adminData = this.getOne(new QueryWrapper<Admin>().lambda()
        .eq(Admin::getUsername, admin.getUsername())
        .eq(Admin::getPassword, password)
        .eq(Admin::getStatus, 1));

        if (adminData == null){
            throw new RRException("管理员不存在");
        }
        return new ResponseVO().put("data", adminData).success();
    }
}
